<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>卖家认证</title>
		<link rel="stylesheet" type="text/css" href="{$_G['addon_url']}/Public/css/weui.css" />
		<link rel="stylesheet" type="text/css" href="{$_G['addon_url']}/Public/css/weui2.css" />
		<link rel="stylesheet" type="text/css" href="{$_G['addon_url']}/Public/css/weui3.css" />
		<link rel="stylesheet" type="text/css" href="{$_G['addon_url']}/Public/css/jquery-weui.min.css" />
		<link rel="stylesheet" type="text/css" href="{$_G['addon_url']}/Public/css/fabu.css" />
		<link rel="stylesheet" type="text/css" href="{$_G['addon_url']}/Public/css/renzheng.css"/>
		<link rel="stylesheet" type="text/css" href="{$_G['addon_url']}/Public/css/imgLoader.css"/>
		<script src="{$_G['addon_url']}/Public/js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="{$_G['addon_url']}/Public/js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="{$_G['addon_url']}/Public/js/zepto.min.js" type="text/javascript" charset="utf-8"></script>
		{:hook('jssdk', false)}
		<!--imgLoader-->
		<script src="{$_G['addon_url']}/Public/js/imgLoader.js" type="text/javascript" charset="utf-8"></script>
		<script>

			$(function(){
                // 初始化上传文件
                $(".img-loader").imgUploaderInit("{:create_mobile_url('upload')}", 1);
                // 如果正在审核或审核通过则显示旧图片
				<if condition="$status == 1 || $status == 2">
                    $("#img1").imgUploaderAppendImg(['{$img1}']);
                    $("#img2").imgUploaderAppendImg(['{$img2}']);
				</if>
            });



			// ajax 提交
			$(function(){
			    $("#submit").on("click", function() {
                    var button = $(this);
                    button.attr({"disabled":"disabled"});

			        var data = {
			            shopName: $("[name=shopName]").val(),
			            mobile: $("[name=mobile]").val(),
						img1: $("#img1").imgUploaderAjaxArgs()[0],
						img2: $("#img2").imgUploaderAjaxArgs()[0]
					};

					$.post("{:create_mobile_url('ajaxAuth')}", data, function(data, status) {
                        if(data.status == 1) {
                            // 成功
                            $.hideLoading();
                            $.toast(data.info);
                        }else if(data.status == 0) {
                            // 失败
                            $.toast(data.info, "forbidden");
                        }
                        if(data.url) {
                            setTimeout(function(){
                                location.href = data.url;
                            }, 2000);
                        }
                        button.removeAttr("disabled");
					});
				});
			});

		</script>
		<style type="text/css">
			.title{
				text-align: center;
				margin:5px 0 ; 
			}
			.shij{

			}
		</style>
	</head>

	<body>
		<div class="weui-header bg-orange">
			<div class="weui-header-left">
				<a class="icon icon-109 f-white" href="javascript:history.go(-1)">返回</a>
			</div>
			<h1 class="weui-header-title">卖家认证</h1>

		</div>
		<form action="" method="post" enctype='multipart/form-data'>
			<div class="weui_cells weui_cells_form">
				<div class="weui_cell">
					<div class="weui_cell_hd"><label class="weui_label">商家名</label></div>
					<div class="weui_cell_bd weui_cell_primary">
						<input name="shopName" class="weui_input" value="{$shopName}" type="text" placeholder="请输入商家名">
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_hd"><label class="weui_label">手机号码</label></div>
					<div class="weui_cell_bd weui_cell_primary">
						<input class="weui_input" name="mobile" type="number" value="{$mobile}" pattern="[0-9]{18}" maxlength="18" placeholder="输入手机号码" emptytips="请输入手机号码" notmatchtips="请输入正确的手机号码">
					</div>
				</div>
			</div>

			<div id="haha">
			<div class="title">工商营业执照</div>
					<div class="container img-loader" id="img1">
						
						<input class="peter-file" type="file" accept="image/jpg,image/jpeg,image/png">
					</div>
					<div class="title">食品经营许可证</div>
					<div class="container img-loader" id="img2">
						
						<input class="peter-file" type="file" accept="image/jpg,image/jpeg,image/png">
					</div>
					<!--<div class="weui_uploader_bd">
						<span>身份证正面照</span>
						<div class="weui_uploader_input_wrp id1">
							<input class="weui_uploader_input" type="file" accept="image/jpg,image/jpeg,image/png,image/gif" id="i1" onchange="previewImage1(this)">
							<input type="hidden" id="i4">
						</div>
					</div>
					<div class="weui_uploader_bd">
						<span>身份证反面照</span>
						<div class="weui_uploader_input_wrp id2">
							<input class="weui_uploader_input" type="file" accept="image/jpg,image/jpeg,image/png,image/gif" id="i2" onchange="previewImage2(this)">
							<input type="hidden" id="i5">
						</div>
					</div>-->
			</div>
			<button name="tijiao" class="weui_btn weui_btn_warn fabu" type="button" id="submit">提交</button>
		</form>
		</div>
		<div style="text-align:center;margin-bottom:145px;">该功能仅对联盟成员开放<br/>入盟请联系010-5748 8855</div>
		<!--
			审核中。。。。
		-->
		<!-- weui_toast_hiden 为隐藏        weui_toast_visible 为显示-->

		<if condition="$status == 1 || $status == 2">
			<div class="weui_toast weui_loading_toast weui_toast_visible" id="suat">
		</if>
		<if condition="$status == 0">
			<div class="weui_toast weui_loading_toast weui_toast_hidden" id="suat">
		</if>
		<if condition="$status == 2">
			<div class="shij">
			</div>
			<p class="weui_toast_content" id="stau"><i class="weui_icon_success" style="margin-right:15px;"></i>审核通过</p>
			<else />
			<div class="shij">
				请等待2~3个工作日
			</div>
			<p class="weui_toast_content" id="stau"><i class="weui_icon_waiting" style="margin-right:15px;"></i>审核中....</p>
		</if>
		</div>
		<!--
			审核中。。。。end、
		-->
		
		
		<!--
			审核通过
		-->                     
		<!-- weui_toast_hiden 为隐藏           weui_toast_visible 为显示-->
		<!--<div class="weui_toast weui_loading_toast weui_toast_visible" id="sccu">
			<p class="weui_toast_content" id="sccu-txt"><i class="weui_icon_success  f30" ></i>审核通过</p>
		</div>-->
		
		

		<!--头部分类信息分类-->

		<!--选择图片上传-->
		<script src="{$_G['addon_url']}/Public/js/lrz.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			function previewImage1(file) {
				var MAXWIDTH = 100;
				var MAXHEIGHT = 200;
				if(file.files && file.files[0]) {
					var reader = new FileReader();
					reader.onload = function(evt) {
						$('.id1').css('background-image', " ").css('background-image', "url(" + evt.target.result + ")");
					};
					reader.readAsDataURL(file.files[0]); //
					console.log(file.files[0]);
				}
			}

			function previewImage2(file) {
				var MAXWIDTH = 100;
				var MAXHEIGHT = 200;
				if(file.files && file.files[0]) {
					var reader = new FileReader();
					reader.onload = function(evt) {
						$('.id2').css('background-image', " ").css('background-image', "url(" + evt.target.result + ")");
					};
					reader.readAsDataURL(file.files[0]); //
					console.log(file.files[0]);
				}
			}

	//	表单提交
			$(document).on("click", ".fabu", function(event) {
				//阻止表单默认提交
				event.preventDefault();
				var name = $('input[name="Username"]').val();
				var img0 = $('input[type="file"]').eq(0).val();
				var img1 = $('input[type="file"]').eq(1).val();
				var userId = $('input[type="number"]').val();
//				alert(userId.length);
				
				
				if(userId.length < 18 && userId.length > 1) {
					$.toast("身份证号码不正确", "forbidden");
					return false;
				}
				if(userId.length > 18) {
					$.toast("身份证号码不正确", "forbidden");
					return false;
				}

				if(!name) {
					$.toptips("姓名不能为空！", 'warning');
					return false;
				} else if(!userId) {
					$.toptips("身份证不能为空！", 'warning');
					return false;
				} else if(!img0 && !img1) {
					$.toptips("请选择图片！", 'warning');
					return false;
				}

				if(name != " " && userId.length == 18 && img0 && img1) {
					$.showLoading();
					setTimeout(function() {
						$.hideLoading();
						$.toast("提交成功");
						setTimeout(function() {
							$('form').submit();    //、表单提交
							
//							$('#suat').removeClass('weui_toast_hiden').addClass('weui_toast_visible');
						}, 1000);
					}, 2500);

				} else {
					$.toast("信息不完整", "forbidden");
					return false;
				}

			});
		</script>

	</body>

</html>